package cn.fintecher.pangolin.service.business.model.request;

import cn.fintecher.pangolin.common.enums.BaseSelect;
import cn.fintecher.pangolin.common.enums.ExportState;
import cn.fintecher.pangolin.common.enums.PayCheckStatus;
import cn.fintecher.pangolin.entity.mysql.QPaymentCheck;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.Objects;

@Data
public class PaymentReplyRequest {

    @ApiModelProperty("委托方id")
    private String principalId;

    @ApiModelProperty("姓名")
    private String personalName;

    @ApiModelProperty("证件")
    private String certificateNo;

    @ApiModelProperty("申请人")
    private String applyName;

    @ApiModelProperty("申请日期小")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date applyDateStart;

    @ApiModelProperty("申请日期大")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date applyDateEnd;

    @ApiModelProperty("是否回复")
    private BaseSelect isReply;

    @ApiModelProperty("导出状态")
    private ExportState exportState;

    public BooleanBuilder generateBooleanBuilder(){
        BooleanBuilder booleanBuilder = new BooleanBuilder();
        QPaymentCheck qPaymentCheck = QPaymentCheck.paymentCheck;
        booleanBuilder.and(qPaymentCheck.isReply.eq(isReply)).and(qPaymentCheck.payCheckStatus.eq(PayCheckStatus.CP));
        if(StringUtils.isNotBlank(principalId)){
            booleanBuilder.and(qPaymentCheck.principalId.eq(principalId));
        }
        if(Objects.nonNull(exportState)){
            booleanBuilder.and(qPaymentCheck.exportState.eq(exportState));
        }
        if(StringUtils.isNotBlank(personalName)){
            booleanBuilder.and(qPaymentCheck.personalName.like(StringUtils.join(personalName,"%")));
        }
        if(StringUtils.isNotBlank(certificateNo)){
            booleanBuilder.and(qPaymentCheck.certificateNo.like(StringUtils.join(certificateNo,"%")));
        }
        if(StringUtils.isNotBlank(applyName)){
            booleanBuilder.and(qPaymentCheck.applyName.like(StringUtils.join(applyName,"%")));
        }
        if (Objects.nonNull(this.applyDateStart)) {
            booleanBuilder.and(booleanBuilder.and(qPaymentCheck.applyDate.goe(this.applyDateStart)));
        }
        if (Objects.nonNull(this.applyDateEnd)) {
            booleanBuilder.and(booleanBuilder.and(qPaymentCheck.applyDate.loe(this.applyDateEnd)));
        }
        return booleanBuilder;
    }
}
